package com.example.java_chatroom_redis_rabbitmq.component;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.concurrent.ConcurrentHashMap;

@Component
public class WebSocketSessionManager {
    private ConcurrentHashMap<Integer, WebSocketSession> hash = new ConcurrentHashMap<>();

    /**
     * 添加会话
     * @param userId
     * @param session
     */
    public void addSession(Integer userId,WebSocketSession session) {
        hash.put(userId,session);
    }

    public WebSocketSession getSessionByUserId(Integer userId) {
        return hash.get(userId);
    }

    public void removeSessionByUserId(Integer userId) {
        hash.remove(userId);
    }
}
